#ifndef GAMECONTROLLER_H
#define GAMECONTROLLER_H

// Include files.
#include <string>
#include "../Service.hpp"
#include "../CompoundService.hpp"

class SystematicRobot;
class DriverStation;

/**
 *  GameController manages controllers that run in a specific game mode.
 */
class GameService :
	public Service
{
	friend class SystematicRobot;
	
	public:
		GameService(SystematicRobot &robot, DriverStation &driverStation);
		virtual ~GameService();
		
		bool GetIsInEnabledMode();
	protected:
		virtual void HandlePeriodic();
	private:
		class Mode
		{
			public:
				typedef void (DriverStation::*SetModeFunction)(bool);
				
				Mode(UINT32 id, std::string name, bool isEnabledMode, SetModeFunction setMode);
				UINT32 GetId() const;
				std::string GetName() const;
				bool GetIsEnabledMode() const;
				CompoundService &GetService();
				
				inline void SetMode(DriverStation &driverStation, bool entering)
				{
					(driverStation.*m_setMode)(entering);
				}
			private:
				UINT32 m_id;
				std::string m_name;
				bool m_isEnabledMode;
				CompoundService m_service;
				SetModeFunction m_setMode;
		};
		
		SystematicRobot &m_robot;
		DriverStation &m_driverStation;
		CompoundService m_serviceEnabled;
		std::set<Mode*> m_modes;
		Mode m_modeDisabled;
		Mode m_modeAutonomous;
		Mode m_modeTeleop;
		Mode m_modeTest;
		Mode *m_modeCurrent;
		
		bool GetIsInMode(Mode &mode);
		void SetMode(Mode &mode);
		void AddMode(Mode &mode);
};

#endif // #ifndef COMPOUNDCONTROLLER_H 
